﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#data_scaling
    /// </summary>
    public class DataScaleParam : IChartParam
    {

        /// <summary>
        /// The name of the API
        /// </summary>
        public string Name { get { return "chds"; } }
        

        /// <summary>
        /// A list of DataScale objects
        /// </summary>
        public List<DataScale> DataScales 
        {
            get { return mDataScales ?? (mDataScales = new List<DataScale>()); }
            set { mDataScales = value; }
        }
        private List<DataScale> mDataScales;


        /// <summary>
        /// The default constructor
        /// </summary>
        public DataScaleParam() { }


        /// <summary>
        /// Constructor to initialize an object with one DataScale
        /// </summary>
        /// <param name="dataScale"></param>
        public DataScaleParam(DataScale dataScale)
        {
            this.DataScales.Add(dataScale);
        }


        /// <summary>
        /// Constructor to initialize an object with more than on DataScale
        /// </summary>
        /// <param name="dataScales"></param>
        public DataScaleParam(DataScale[] dataScales)
        {
            foreach (DataScale dataScale in dataScales)
                this.DataScales.Add(dataScale);
        }


        /// <summary>
        /// Render the API text
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=", this.Name));

            foreach (DataScale dataScale in this.DataScales)
                sb.Append(String.Format("{0},{1},", dataScale.Minimum.ToString(), dataScale.Maximum.ToString()));

            sb.Remove(sb.ToString().LastIndexOf(','), 1);

            return sb.ToString();
        }
    }


    public class DataScale
    {
        /// <summary>
        /// The lower limit of data values to dsplay
        /// </summary>
        public float Minimum { get; set; }


        /// <summary>
        /// The upper limit of data values to display
        /// </summary>
        public float Maximum { get; set; }


        /// <summary>
        /// Constructor to initialize all properties
        /// </summary>
        /// <param name="minimum"></param>
        /// <param name="maximum"></param>
        public DataScale(float minimum, float maximum)
        {
            this.Minimum = minimum;
            this.Maximum = maximum;
        }
    }
}
